import {
  ActionReducer,
  ActionReducerMap,
  createFeatureSelector,
  createSelector,
  MetaReducer
} from '@ngrx/store';
import { environment } from '../../environments/environment';
import * as fromCounter from './reducers/counter.reducer';
import * as fromMemo from './reducers/memo.reducer';
import {MemoFeatureKey} from "./reducers/memo.reducer";


export interface AppState {
  [fromCounter.counterFeatureKey]: fromCounter.State;
  [fromMemo.MemoFeatureKey]: fromMemo.State;
}

export const reducers: ActionReducerMap<AppState> = {
  [fromCounter.counterFeatureKey]: fromCounter.reducer,
  [fromMemo.MemoFeatureKey]: fromMemo.reducer,
};

function intercept(reducer: ActionReducer<any>): ActionReducer<any> {
  return function (state, action) {
    // console.log(state, action);
    return reducer(state, action)
  }
}

export const metaReducers: MetaReducer<AppState>[] = !environment.production ? [intercept] : [intercept];
